<template>
  <div class="house-list">
    <div class="page-center">
      <a-row justify="space-between" align="middle">
        <a-col>
          <div class="info-title">{{ listTitle }}</div>
        </a-col>
        <a-col>
          <span class="more-button" @click="onMoreClick">
             更多
              <DoubleRightOutlined />
          </span>
        </a-col>
      </a-row>
      <a-row class="list">
        <div
          class="house-item"
          v-for="(item, index) in list"
          :key="index"
          @click="onHouseClick(item)"
        >
          <div class="house-item-card">
            <div class="house-item-img">
              <img :src="item.logo" alt="" v-if="item.logo"/>
              <img
                :src="item.images[0]"
                v-else-if="item.images && item.images.length"
              />
              <img
                src="../../../../common/images/home/building_no_pic.png"
                alt=""
                v-else
              />
            </div>
            <!-- <div
            class="house-item-img"
            :style="{ backgroundImage: 'url(' + item.img + ')' }"
          ></div> -->
            <div class="house-item-card-bottom">
              <div class="flex align-center justify-between">
                <div class="house-item-name">{{ item.name }}</div>
                <div class="house-item-price">
                  <template v-if="roomType">
                    <span style="font-size: 18px">{{ item.build_area }}</span>
                    <span>㎡</span>
                  </template>
                  <template v-else>
                    <span style="font-size: 18px">{{
                        item.room_min_price || 0
                      }}</span>
                    <span>元/㎡/月 起</span>
                  </template>
                </div>
              </div>
              <div class="house-item-address">{{ item.district_address }}</div>
            </div>
          </div>
        </div>
      </a-row>
    </div>
  </div>
</template>

<script>
import {
  defineComponent,
  reactive,
  toRefs,
  computed,
  watch,
  toRaw,
  h,
  onBeforeUnmount,
} from "vue";
import { DoubleRightOutlined } from "@ant-design/icons-vue";
import {useRouter} from "vue-router";
export default defineComponent({
  name: "HouseList",
  components: {DoubleRightOutlined,},
  props: {
    listTitle: {
      type: String,
      default: "",
    },
    list: {
      type: Array,
      default: () => [],
    },
    roomType: {
      type: Boolean,
      default: false,
    },
  },
  setup(props, context) {
    const router = useRouter();
    const state = reactive({});

    const onHouseClick = (item) => {
      context.emit("onItemClick", item);
    };

    const onMoreClick = (item) => {
      context.emit("onMoreClick", item);
    };

    const init = () => {
    };

    init();

    return {
      ...toRefs(state),
      onHouseClick,
      onMoreClick,
    };
  },
});
</script>
<style lang="less" scoped>
.house-list {
  //padding-top: 20px;
  //padding-bottom: 20px;

  .page-center {
    //margin: 0 80px;
  }

  .full-width {
    width: 100%;
  }

  .full-height {
    height: 100%;
  }

  .flex {
    display: flex;
  }

  .justify-center {
    justify-content: center;
  }

  .justify-between {
    justify-content: space-between;
  }

  .align-center {
    align-items: center;
  }

  .list-title {
    font-size: 20px;
    font-weight: 600;
  }

  .more-button {
    color: #999;
    cursor: pointer;
  }

  .more-button:hover {
    color: @primary-color;
  }

  .list {
    .house-item {
      width: 25%;
      padding: 15px;
      cursor: pointer;
      .house-item-card {
        width: 100%;
        background-color: #fff;
        border-radius: 6px;
        overflow: hidden;

        .house-item-img {
          width: 100%;
          height: 150px;
          object-fit: cover;
          overflow: hidden;

          background-repeat: no-repeat;
          background-size: cover;
          background-position: center center;

          img {
            width: 100%;
            height: 100%;
            object-fit: cover;
            transition: 0.3s;
          }
        }

        .house-item-card-bottom {
          padding: 20px;

          .house-item-name {
            font-weight: 600;
            font-size: 18px;
            flex: 1;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
          }

          .house-item-price {
            color: red;
          }

          .house-item-address {
            margin-top: 5px;
            color: #999;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
          }
        }
      }
    }

    .house-item:first-child {
      padding-left: 0;
    }

    .house-item:last-child {
      padding-right: 0;
    }

    .house-item:hover {
      .house-item-card {
        box-shadow: -6px -6px 20px rgba(255, 255, 255, 1),
        6px 6px 20px rgba(0, 0, 0, 0.1);
      }

      .house-item-img img {
        transform: scale(1.1);
      }
    }
  }
}
.house-item-card-bottom {
  border: 1px solid #eee!important;
}
.info-title{
  display: flex;
  align-items: center;
  font-size: 18px;
  font-weight: 600;
  color: #000;
  margin-right: 20px;
  &::before{
    display: inline-block;
    content: '';
    height: 14px;
    width: 4px;
    background: #2681f3;
    margin-right: 5px;
    border-radius: 2px;
  }
}
</style>
